package com.neusoft.yuejian26.yuejian_26.Activity;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.jcodecraeer.xrecyclerview.XRecyclerView;
import com.neusoft.yuejian26.yuejian_26.Adapter.ReplyAdapter;
import com.neusoft.yuejian26.yuejian_26.Bean.ShareSimpbean;
import com.neusoft.yuejian26.yuejian_26.Bean.Userbean;
import com.neusoft.yuejian26.yuejian_26.R;
import com.neusoft.yuejian26.yuejian_26.model.PostModel;
import com.neusoft.yuejian26.yuejian_26.model.UserModel;
import com.neusoft.yuejian26.yuejian_26.network.RetrofitCallback;
import com.squareup.picasso.Picasso;

import java.util.List;

import de.hdodenhof.circleimageview.CircleImageView;
import retrofit2.Call;

public class ShareSimpActivity extends AppCompatActivity {

    public ImageView svg_back,sharesimp_pic;
    public CircleImageView sharesimp_upic;
    public TextView sharesimp_uname,sharesimp_content;
    public XRecyclerView reply_list;
    public String pid=null;
    public String uid=null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_share_simp);
        initView();
        initEvent();
        getShareSimp();
    }

    private void getShareSimp(){
        Bundle bundle=this.getIntent().getExtras();
        pid = bundle.getString("pid");
        PostModel postModel = new PostModel();
        Call call = postModel.shareSimp(pid);
        postModel.bindCallback(call, new RetrofitCallback() {
            @Override
            public void onResponse(Object o) {
                ShareSimpbean ssdata = (ShareSimpbean) o;
                getUserData(ssdata.getUid());
                Picasso.with(ShareSimpActivity.this)
                        .load("http://115.159.93.244/new18yuejian/Public/upload/"+ssdata.getPostfile())
                        .into(sharesimp_pic);
                sharesimp_content.setText(ssdata.getPtext());
                reply_list.setAdapter(new ReplyAdapter(ShareSimpActivity.this,ssdata.getReplay()));
            }
        });
    }

    private void getUserData(String uid){
        UserModel userModel = new UserModel();
        Call call = userModel.userIntro(uid);
        userModel.bindCallback(call, new RetrofitCallback() {
            @Override
            public void onResponse(Object o) {
                Userbean udata = (Userbean) o;
                Picasso.with(ShareSimpActivity.this)
                        .load("http://115.159.93.244/new18yuejian/Public/upload/"+udata.getUserpic())
                        .into(sharesimp_upic);
                sharesimp_uname.setText(udata.getUname());
            }
        });
    }

    private void initView(){
        sharesimp_uname= (TextView) findViewById(R.id.sharesimp_uname);
        sharesimp_content= (TextView) findViewById(R.id.sharesimp_content);
        sharesimp_pic= (ImageView) findViewById(R.id.sharesimp_pic);
        sharesimp_upic= (CircleImageView) findViewById(R.id.sharesimp_upic);
        reply_list= (XRecyclerView) findViewById(R.id.reply_list);
        svg_back= (ImageView) findViewById(R.id.svg_back);
    }
    private void initEvent(){
        reply_list.setLayoutManager(new LinearLayoutManager(ShareSimpActivity.this));
        svg_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
    }

}
